class Solution {
    public
        int numberOfArithmeticSlices(vectorint& nums) {
            int n = nums.size();
            vectorvectorint dp(n,vectorint(n,0));dp[i][j]表示以ij位置为结尾的子序列个数
            unordered_maplong long,vectorint hash;
            for(int i = 0 ; i  n ; i++){
                hash[nums[i]].push_back(i);
            }
            int ret = 0;
            for(int i = 1 ; i  n ; i++){
                for(int j = i+1 ; j  n ; j++){
                    long long target = (long long)2nums[i]-nums[j];
                    if(hash.count(target)){
                        for(auto k  hash[target]){
                            if(k  i)
                                dp[i][j] += dp[k][i]+1;
                        }
                    }
                    ret += dp[i][j];
                }
            }
            return ret;
        }
    };